function [paths, function_iterations] = dfs3(adjacency_matrix, visited_nodes, end_node, paths, locations, function_iterations, trust)


if trust == 0
   neighbours = get_neighbour_nodes(adjacency_matrix, visited_nodes(end));
else
   neighbours = get_neighbours_trust_sort(adjacency_matrix, visited_nodes(end));
end

%neighbours = get_neighbours_trust_sort(adjacency_matrix, visited_nodes(end));
%neighbours = get_neighbour_nodes(adjacency_matrix, visited_nodes(end));
neighbours = distance_sort(end_node, neighbours, locations);

for i=1:length(neighbours)
    node = neighbours(i);
    if any(visited_nodes(:) == node)
        continue
    end
    if node == end_node
        visited_nodes(end+1) = node;
        paths{end + 1} = visited_nodes;
        %visited_nodes
        visited_nodes = visited_nodes(1:end-1);
        break
    end
end


for i=1:length(neighbours)
    node = neighbours(i);
    
    if length(visited_nodes) > 100 | function_iterations > 1000
        break
    end
    
    if any(visited_nodes(:) == node) | node == end_node
        continue
    end
    
     visited_nodes(end+1) = node;
     function_iterations = function_iterations + 1;
     if length(paths) < 1
        [paths, function_iterations] = dfs3(adjacency_matrix, visited_nodes, end_node, paths, locations, function_iterations, trust);
     else
         break
     end
     visited_nodes = visited_nodes(1:end-1);
end

end